package com.itany.utils;

import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtils {
    /**
     * 判断字符串是否为null或空
     *
     * @param str
     * @return
     */

    public static boolean isEmpty(String str) {
        return str == null || str.length() == 0;
    }

    /**
     * 校验isbn格式合规 13纯数字
     *
     * @param isbn
     * @return
     */
    public static boolean isIsbn(String isbn) {
        return isbn != null && isbn.matches("^\\d{13}|\\d{10}$");
    }

    public static String trim(String str) {
        return str == null ? null : str.trim();
    }


    /**
     * 文件用UUID重命名，保留格式后缀
     *
     * @param fileName
     * @return
     */
    public static String rename(String fileName) {
        int lastDot = fileName.lastIndexOf(".");
        String suffix = fileName.substring(lastDot);
        return idGenerate() + suffix;
    }

    /**
     * UUID.randomUUID()
     *
     * @return
     */
    public static String idGenerate() {
        return UUID.randomUUID().toString();
    }


    /**
     * 获取第一个数字
     *
     * @param input
     * @return
     */
    public static String getPrice(String input) {
        Pattern pattern = Pattern.compile("\\d{1,4}(\\.\\d{1,4})?");
        Matcher matcher = pattern.matcher(input);
        while (matcher.find()) {
//            return matcher.group(0);
            return matcher.group();
        }
        return null;
    }


    public static String getIsbn(String input) {
//        Pattern pattern = Pattern.compile("\\d{13,}");
//        Matcher matcher = pattern.matcher(input);
//        while (matcher.find()) {
//            return matcher.group();
//        }
//        return null;

        return input.substring(5).trim();

    }

    public static void main(String[] args) {

//        String soup = "aasda1.121111aaaasdas";
//        String price = getPrice(soup);
//        System.out.println(price);

//
        String isbn = "ISBN：97875321505261 ";
        String isbn2 = "ISBN：9787532150 ";

        System.out.println(isIsbn(getIsbn(isbn)));
    }
}
